import api from './api' // 导入 api
import config from './config.js' // 倒入默认配置
// import store from '@/store/index'

let baseURL
// 根据环境来设置接口请求
if (process.env.NODE_ENV === 'development') {
  baseURL = config.baseURL.dev
} else if (process.env.NODE_ENV === 'debug') {
  baseURL = config.baseURL.dev
} else if (process.env.NODE_ENV === 'production') {
  baseURL = config.baseURL.production
}

/* 将所有接口统一起来便于维护 */

// 登录
// export const login = (username, password) => {
//   return api({
//     url: '/user/login',
//     method: 'post',
//     data: {
//       username: username,
//       password: password
//     }
//   })
// }
export const login = data => {
  return api({
    url: '/user/login',
    method: 'post',
    data: data
  })
}

// 退出
export const logout = data => {
  return api({
    url: '/user/logout',
    method: 'post',
    data: data
  })
}

// 注册
export const register = data => {
  return api({
    url: '/user/register',
    method: 'post',
    data: data
  })
}

// 发送短信验证码
export const sendSmsCode = (mobile,type) => {
  return api({
    url: '/user/send_sms',
    method: 'post',
    data: {
      mobile: mobile,
      type: type || 1
    }
  })
}

// 获取用户信息
export const getUser = data => {
  return api({
    url: '/user/info',
    method: 'post',
    data
  })
}

// 默认全部导入
export default {
  login,
  register,
  sendSmsCode,
  getUser,
  logout
}
